#ifndef MYSERIALPORT_H
#define MYSERIALPORT_H

#include <QObject>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QTimer>

#define ENCODING_TYPE_GBK       0
#define ENCODING_TYPE_UTF8      1

class MySerialPort : public QSerialPort
{
    Q_OBJECT
public:
    MySerialPort();
    ~MySerialPort(void);

    bool spOpen();
    void spClose();
    QByteArray spReadAll();
    qint64 spWrite(QByteArray &byteArray);

    QSerialPort * m_SerialPort;
    QString m_SpName;
    qint32 m_BaudRate;
    DataBits m_DataBit;
    StopBits m_StopBit;
    Parity m_Parity;
    bool m_OpenFlag;
    qint32 m_BytesAvailable; //接收到的可读数据
    bool m_NeedTimeStamp;
    quint64 m_RxByteCnt;
    quint64 m_TxByteCnt;
    bool m_HexSendFlag;
    bool m_HexShowFlag;
    bool m_NewLineFlag;
    int m_EncodingType;

private:
    QTimer *m_RecvTimer;

signals:
    void signalSerialPortRecvShow(QString data);

public slots:
    void slotSerialPortRecv();
};

#endif // MYSERIALPORT_H
